function formatTimestampToDate(timestamp, format) {
  　　const formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
  　　let returnArr = [];
  　　let date = new Date(timestamp); 
  　　let year = date.getFullYear()
  　　let month = date.getMonth() + 1
  　　let day = date.getDate()
  　　let hour = date.getHours()
  　　let minute = date.getMinutes()
  　　let second = date.getSeconds()
  　　returnArr.push(year, month, day, hour, minute, second);
  　　returnArr = returnArr.map(formatNumber);
  　　for (var i in returnArr) {
  　　format = format.replace(formateArr[i], returnArr[i]);
  }
  　　return format;
  }
const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

/**
 * @param {Function} func
 * @param {number} wait
 * @param {boolean} immediate
 * @return {*}
 */
export function debounce(func, wait) {
  // wait：500ms；func：被频繁触发的事件
  let timeout;
  return function () {
    let context = this;
    let args = arguments;
    let later = () => {
      timeout = null;
      func.apply(context, args);
    };
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
  }
}

module.exports = {
  formatTimestampToDate,
  debounce
}
